package controllers.cpanel;

import java.util.Date;

import models.Post;
import models.Tag;
import play.mvc.Controller;
import play.mvc.With;
import controllers.Secure;

@With(Secure.class)
public class Admin extends Controller {

	public static void index() {
		render();
	}

	public static void form(){
		render();
	}
	public static void save(String title,String content,Boolean status,String tags) {
		Post post = new Post(title,content,status);
		// Set tags list
	    for(String tag : tags.split("\\s+")) {
	        if(tag.trim().length() > 0) {
	        	post.tags.add(Tag.findOrCreateByName(tag));
	        }
	    }
	    // Validate
	    validation.valid(post);
	    if(validation.hasErrors()) {
	        render("@form", post);
	    }
	    // Save
	    post.save();
	    index();
	}
}
